import QtQuick 2.5
import QtQuick.Controls 2.1
import ".."

ComboBox
{
    id: control
    font.family: Common.fontMain
    font.pixelSize: 16
    delegate: ItemDelegate
    {
        width: control.width
        contentItem: Text
        {
            text: modelData
            color: Common.colorTextBlack
            font: control.font
            elide: Text.ElideRight
            verticalAlignment: Text.AlignVCenter
        }
        highlighted: control.highlightedIndex === index
    }

    indicator: Image
    {
        source: "qrc:/Images/combox_" + (popup.visible ? "up" : "down") + ".png"
        anchors.verticalCenter: control.verticalCenter
        anchors.right: control.right
        anchors.rightMargin: 10
    }

    contentItem: Label
    {
        leftPadding: 15
        rightPadding: control.indicator.width + control.spacing
        text: control.displayText
        font: control.font
        color: Common.colorTextBlack
        horizontalAlignment: Text.AlignLeft
        verticalAlignment: Text.AlignVCenter
        elide: Text.ElideRight
    }

    background: Rectangle
    {
        border.color: Common.colorText
        border.width: 1
        color: control.enabled ? "white" : Common.colorInvalid
        radius: 5
    }

    popup: Popup
    {
        y: control.height - 1
        width: control.width
        height: listview.count >= 5 ? control.height * 5 : control.height * listview.count
        padding: 1
        contentItem: ListView
        {
            id: listview
            clip: true
            implicitHeight: contentHeight
            model: control.popup.visible ? control.delegateModel : null
            currentIndex: control.highlightedIndex
            ScrollIndicator.vertical: ScrollIndicator{}
        }
        background: Rectangle
        {
            border.width: 1
            border.color: Common.colorText
            radius: 5
        }
    }
}
